home *** CD-ROM | disk | FTP | other *** search
- // PIDView.cpp : implementation of the CPIDView class
- //
-
- #include "stdafx.h"
- #include "PID.h"
-
- #include "PIDDoc.h"
- #include "PIDView.h"
-
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
-
- /////////////////////////////////////////////////////////////////////////////
- // CPIDView
-
- IMPLEMENT_DYNCREATE(CPIDView, CFormView)
-
- BEGIN_MESSAGE_MAP(CPIDView, CFormView)
- //{{AFX_MSG_MAP(CPIDView)
- // NOTE - the ClassWizard will add and remove mapping macros here.
- // DO NOT EDIT what you see in these blocks of generated code!
- //}}AFX_MSG_MAP
- // Standard printing commands
- ON_COMMAND(ID_FILE_PRINT, CFormView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CFormView::OnFilePrint)
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CFormView::OnFilePrintPreview)
- END_MESSAGE_MAP()
-
- /////////////////////////////////////////////////////////////////////////////
- // CPIDView construction/destruction
-
- CPIDView::CPIDView()
- : CFormView(CPIDView::IDD)
- {
- //{{AFX_DATA_INIT(CPIDView)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- // TODO: add construction code here
-
- }
-
- CPIDView::~CPIDView()
- {
- }
-
- void CPIDView::DoDataExchange(CDataExchange* pDX)
- {
- CFormView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CPIDView)
- DDX_Control(pDX, IDC_RTPIDXCTRL1, m_PIDControl);
- DDX_Control(pDX, IDC_SCROLLXCTRL1, m_ScrollGraph);
- //}}AFX_DATA_MAP
- }
-
- BOOL CPIDView::PreCreateWindow(CREATESTRUCT& cs)
- {
- // TODO: Modify the Window class or styles here by modifying
- // the CREATESTRUCT cs
-
- return CFormView::PreCreateWindow(cs);
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CPIDView printing
-
- BOOL CPIDView::OnPreparePrinting(CPrintInfo* pInfo)
- {
- // default preparation
- return DoPreparePrinting(pInfo);
- }
-
- void CPIDView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add extra initialization before printing
- }
-
- void CPIDView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
- {
- // TODO: add cleanup after printing
- }
-
- void CPIDView::OnPrint(CDC* pDC, CPrintInfo*)
- {
- // TODO: add code to print the controls
- }
-
- /////////////////////////////////////////////////////////////////////////////
- // CPIDView diagnostics
-
- #ifdef _DEBUG
- void CPIDView::AssertValid() const
- {
- CFormView::AssertValid();
- }
-
- void CPIDView::Dump(CDumpContext& dc) const
- {
- CFormView::Dump(dc);
- }
-
- CPIDDoc* CPIDView::GetDocument() // non-debug version is inline
- {
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CPIDDoc)));
- return (CPIDDoc*)m_pDocument;
- }
- #endif //_DEBUG
-
- /////////////////////////////////////////////////////////////////////////////
- // CPIDView message handlers
-
- BEGIN_EVENTSINK_MAP(CPIDView, CFormView)
- //{{AFX_EVENTSINK_MAP(CPIDView)
- ON_EVENT(CPIDView, IDC_RTPIDXCTRL1, 1 /* OnInternalTimer */, OnOnInternalTimerRtpidxctrl1, VTS_NONE)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
-
- void CPIDView::OnOnInternalTimerRtpidxctrl1()
- { double rValues[3];
-
- rMeasured += (rOutput / 20);
- rOutput = m_PIDControl.CalcPID(rMeasured);
-
- m_PIDControl.UpdatePIDBargraph(rMeasured, rSetpoint, rOutput);
-
- rValues[0] = rSetpoint;
- rValues[1] = rMeasured;
- rValues[2] = rOutput;
- m_ScrollGraph.UpdateDynData(0,rValues);
- }
-
- void CPIDView::OnInitialUpdate()
- {
- CFormView::OnInitialUpdate();
-
- rMeasured = 32;
- rOutput = 0.0;
- rSetpoint = 68;
-
- m_PIDControl.SetPIDSetpoint(rSetpoint);
- m_PIDControl.SetEnableInternalTimer(TRUE);
- }
-